package com.lxp.ssh2.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.lxp.ssh2.dao.BaseDAO;
import com.lxp.ssh2.dao.UserDAO;
import com.lxp.ssh2.po.User;

@Repository
public class UserDAOImpl extends BaseDAO implements UserDAO {

	@Override
	public List<User> findAll() {
		String hql = "from User";
		return this.getHibernateTemplate().find(hql);
	}

	@Override
	public User findByAccount(String account) {
		User user = null;
		String hql = "from User u where u.account = ?";
		List<User> list = this.getHibernateTemplate().find(hql, account);
		if(!list.isEmpty()) {
			user = list.get(0);
		}
		return user;
	}

	/* (non-Javadoc)
	 * @see com.lxp.ssh2.dao.UserDAO#add(com.lxp.ssh2.po.User)
	 */
	@Override
	public void add(User user) {
		this.getHibernateTemplate().save(user);
	}

}
